import os

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template

class BaseHandler(webapp.RequestHandler):
	def initialize(self, request, response):
		"""General initialization for every request"""
		super(BaseHandler, self).initialize(request, response)
	
	def log_exception(self, ex):
		"""Internal logging handler to reduce some App Engine noise in errors"""
		msg = ((str(ex) or ex.__class__.__name__) +
				u': \n' + traceback.format_exc())
		if isinstance(ex, urlfetch.DownloadError) or \
		   isinstance(ex, DeadlineExceededError) or \
		   isinstance(ex, CsrfException) or \
		   isinstance(ex, taskqueue.TransientError):
			logging.warn(msg)
		else:
			logging.error(msg)
			
	def render(self, name, **data):
		"""Render a template"""
		if not data:
			data = {}
		self.response.out.write(template.render(
			os.path.join(
				os.path.dirname(__file__), 'templates', name + '.html'),
			data))

class MainPage(BaseHandler):
	def get(self):
		self.render(u'home',
					passed = 'True')

application = webapp.WSGIApplication(
									 [('/', MainPage)],
									 debug=True)

def main():
	run_wsgi_app(application)

if __name__ == "__main__":
    main()